package com.cctc.rds.nrpc.api.connection.server;

import java.util.ArrayList;
import java.util.List;

public class ServerConnectionListenerProvider {
    private static class ServerConnectionListenerProviderHolder {
        private static final ServerConnectionListenerProvider INSTANCE = new ServerConnectionListenerProvider();
    }

    private ServerConnectionListenerProvider() {
        this.listeners = new ArrayList<>();
    }

    public static ServerConnectionListenerProvider getInstance() {
        return ServerConnectionListenerProviderHolder.INSTANCE;
    }

    private List<ServerConnectionListener> listeners;

    public synchronized void registry(ServerConnectionListener listener) {
        listeners.add(listener);
    }

    public synchronized void remove(ServerConnectionListener listener) {
        listeners.remove(listener);
    }

    public synchronized List<ServerConnectionListener> list() {
        return listeners;
    }

}
